package com.qfedu.api.controller.product;

import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.product.service.ProductService;
import com.qfedu.common.api.CommonPage;
import com.qfedu.common.api.CommonResult;
import com.qfedu.mbg.model.*;
import io.swagger.models.auth.In;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;
import java.util.List;
import java.util.Map;

/**
 * @author Z ym
 * @create 2024-07-11 20:09
 * @desc
 */
@RestController
public class ProductController {

    @Autowired
    private ProductService productService;

    /**
     * 查询生产工单列表
     */
    @RequestMapping("/product/list")
    public CommonResult<CommonPage<ProductList>> list(@RequestParam Map<String,Object> map) {
        // 条件查询
        List<ProductList> productResultList = productService.selectProductByCondition(map);
        // 分页
        Page page =PageHelper.startPage(1, 5);
        Long pageTotal=page.getTotal();
        return CommonResult.success(CommonPage.restPage(productResultList,pageTotal));
    }

    /**
     * 删除生产工单
     */
    @RequestMapping("/delete")
    public CommonResult remove(String productId) {
        return CommonResult.success(productService.deleteByExample(Integer.valueOf(productId)));
    }

    /**
     * 导出生产工单列表
     */
    @RequestMapping("/export")
    public void export(HttpServletResponse response)
    {
        // List<ProWorkorder> list = proWorkorderService.selectProWorkorderList(proWorkorder);
        // ExcelUtil<ProWorkorder> util = new ExcelUtil<ProWorkorder>(ProWorkorder.class);
        // util.exportExcel(response, list, "生产工单数据");
    }

    /**
     * 导入生产工单列表
     */
    @RequestMapping("/import")
    public void importProductList(HttpServletResponse response)
    {
        // List<ProWorkorder> list = proWorkorderService.selectProWorkorderList(proWorkorder);
        // ExcelUtil<ProWorkorder> util = new ExcelUtil<ProWorkorder>(ProWorkorder.class);
        // util.exportExcel(response, list, "生产工单数据");
    }

    /**
     * 新增产品
     */
    @RequestMapping("/product/add")
    public CommonResult add(@RequestBody ProductTable productTable) {
        return CommonResult.success(productService.insert(productTable));
    }

    /**
     * 修改产品
     */
    @RequestMapping("/product/edit")
    public CommonResult edit(@RequestBody ProductTable productTable) {
        return CommonResult.success(productService.edit(productTable));
    }

    /**
     * 工艺流程展示
     */
    @RequestMapping("/product/craftProcessShow")
    public CommonResult craftProcessShow(String productId) {
        return CommonResult.success(productService.craftProcessShow(Integer.valueOf(productId)));
    }

    /**
     * 工艺流程列表
     */
    @RequestMapping("/product/craftProcessList")
    public CommonResult craftProcessList() {
        return CommonResult.success(productService.craftProcessList());
    }

    /**
     * 工序列表
     */
    @RequestMapping("/product/structureList")
    public CommonResult structureList() {
        return CommonResult.success(productService.structureList());
    }

    /**
     * 设备清单列表
     */
    @RequestMapping("/product/equipmentList")
    public CommonResult equipmentList() {
        return CommonResult.success(productService.equipmentList());
    }

    /**
     * 原材料清单列表
     */
    @RequestMapping("/product/materialsList")
    public CommonResult materialsList() {
        return CommonResult.success(productService.materialsList());
    }

    /**
     * 辅料清单列表
     */
    @RequestMapping("/product/ingredientsList")
    public CommonResult ingredientsList() {
        return CommonResult.success(productService.ingredientsList());
    }

    /**
     * 刀具清单列表
     */
    @RequestMapping("/product/cutterList")
    public CommonResult cutterList() {
        return CommonResult.success(productService.cutterList());
    }

    /**
     * 设备清单增加
     */
    @RequestMapping("/product/equipmentAdd")
    public CommonResult equipmentAdd(EquipmentLedger equipmentLedger) {
        return CommonResult.success(productService.equipmentAdd(equipmentLedger));
    }

    /**
     * 原材料清单增加
     */
    @RequestMapping("/product/materialsAdd")
    public CommonResult materialsAdd(Materials materials) {
        return CommonResult.success(productService.materialsAdd(materials));
    }

    /**
     * 辅料清单增加
     */
    @RequestMapping("/product/ingredientsAdd")
    public CommonResult ingredientsAdd(Ingredients ingredients) {
        return CommonResult.success(productService.ingredientsAdd(ingredients));
    }

    /**
     * 刀具清单增加
     */
    @RequestMapping("/product/cutterAdd")
    public CommonResult cutterAdd(Cutter cutter) {
        return CommonResult.success(productService.cutterAdd(cutter));
    }

}
